package com.wenhui.schoolyardinfo.mine.model;

import android.content.Context;

import com.wenhui.schoolyardinfo.manager.Okhttp3Manager;
import com.wenhui.schoolyardinfo.mine.callback.OnAuthenticationDataListener;
import com.wenhui.schoolyardinfo.mine.callback.OnMineAlbumListener;
import com.wenhui.schoolyardinfo.mine.callback.OnMineListener;
import com.wenhui.schoolyardinfo.mine.callback.OnPersonalDataListener;
import com.wenhui.schoolyardinfo.mine.model.base.IMineModel;

import java.io.IOException;
import java.util.Map;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

/**
 * author    : Urasaki
 * e-mail    : 1164688204@qq.com
 * date      : 2019/7/9 17:03
 * introduce :
 */

public class MineModelImpl implements IMineModel {

    private Context context;
    private Okhttp3Manager okhttp3Manager;

    public MineModelImpl(Context context) {
        this.context = context;
    }

    @Override
    public void getMineData(Map<String, String> bodyParams, final OnMineListener onMineListener) {
        okhttp3Manager = Okhttp3Manager.getInstance(context);
        okhttp3Manager.postAsyncFormOkhttp3("",
                null,
                bodyParams,
                new Callback() {
                    @Override
                    public void onFailure(Call call, IOException e) {
                        onMineListener.onGetMineDataError(e.toString());
                    }

                    @Override
                    public void onResponse(Call call, Response response) throws IOException {
                        onMineListener.onGetMineDataSuccess(response.body().string());
                    }
                });
    }

    @Override
    public void getPersonalData(Map<String, String> bodyParams, final OnPersonalDataListener onPersonalDataListener) {
        okhttp3Manager = Okhttp3Manager.getInstance(context);
        okhttp3Manager.postAsyncFormOkhttp3("",
                null,
                bodyParams,
                new Callback() {
                    @Override
                    public void onFailure(Call call, IOException e) {
                        onPersonalDataListener.onGetPersonalDataError(e.toString());
                    }

                    @Override
                    public void onResponse(Call call, Response response) throws IOException {
                        onPersonalDataListener.onGetPersonalDataSuccess(response.body().string());
                    }
                });
    }

    @Override
    public void getMineAlbum(Map<String, String> bodyParams, final OnMineAlbumListener onMineAlbumListener) {
        okhttp3Manager = Okhttp3Manager.getInstance(context);
        okhttp3Manager.postAsyncFormOkhttp3("",
                null,
                bodyParams,
                new Callback() {
                    @Override
                    public void onFailure(Call call, IOException e) {
                        onMineAlbumListener.onGetMineAlbumError(e.toString());
                    }

                    @Override
                    public void onResponse(Call call, Response response) throws IOException {
                        onMineAlbumListener.onGetMineAlbumSuccess(response.body().string());
                    }
                });
    }

    @Override
    public void getAuthenticationData(Map<String, String> bodyParams, final OnAuthenticationDataListener onAuthenticationDataListener) {
        okhttp3Manager = Okhttp3Manager.getInstance(context);
        okhttp3Manager.postAsyncFormOkhttp3("",
                null,
                bodyParams,
                new Callback() {
                    @Override
                    public void onFailure(Call call, IOException e) {
                        onAuthenticationDataListener.onGetAuthenticationDataError(e.toString());
                    }

                    @Override
                    public void onResponse(Call call, Response response) throws IOException {
                        onAuthenticationDataListener.onGetAuthenticationDataSuccess(response.body().string());
                    }
                });
    }

}
